import util.HttpRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pp.IWorkTimeStrategy;
import pp.PowerProject;
import pp.strategy.worktime.WorkTimeStrategyEnum;
import properties.AutoBGProperties;
import properties.WorkTimeBean;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * @author liufei
 * @Description
 * @Date 2020/11/2 14:53
 */
public class BgSingerMain {

    public static void main(String[] args) throws Exception {
        new BgSingerMain().deal();
    }

    public void deal() throws Exception {
        AutoBGProperties autoBGProperties = AutoBGProperties.readProperties();
        String firstDay = autoBGProperties.getFirstDay();

        System.out.println("===============================================================");
        System.out.println("确定是报[" + firstDay + "]的工时吗？ 回车确认，no退出");
        System.out.println("===============================================================");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        if (s.equalsIgnoreCase("no")) {
            System.out.println("结束");
            return;
        }
        HttpRequest httpRequest = new HttpRequest();
        PowerProject powerProject = new PowerProject(httpRequest, autoBGProperties);
        boolean login = powerProject.login();
        if (login){
            IWorkTimeStrategy iWorkTimeStrategy = WorkTimeStrategyEnum.newStrategy(autoBGProperties.getReportForWorkType(), powerProject);
            Map<String, WorkTimeBean> stringWorkTimeBeanMap = iWorkTimeStrategy.workTime(autoBGProperties);
            for (Map.Entry<String, WorkTimeBean> entry : stringWorkTimeBeanMap.entrySet()) {
                powerProject.saveTimesheet(entry.getKey(), entry.getValue());
            }
            powerProject.printTimesheetFields();
        }
    }

}
